package com.sptpc.hellospring;

import com.sptpc.hellospring.model.Category;
import com.sptpc.hellospring.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;

import java.util.List;

@Slf4j
@SpringBootApplication
public class HelloSpringApplication implements ApplicationRunner {

    @Autowired
    private CategoryService categoryService;


    public static void main(String[] args) {
        SpringApplication.run(HelloSpringApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {

//        Category category = categoryService.savaCategory("果汁");
//        log.info("创建一个新的分类：{}",category);

//        List<Category>  categoryList = categoryService.findAll();
//        categoryList.forEach(c -> {
//            log.info("分类：{}",c);
//        });

//        Category category = categoryService.findOne("果%");
//        log.info("查找分类：{}",category);

        Category category = categoryService.update((long)1,"奶茶");
        log.info("更新分类:{}",category);

    }
}